package com.ruoyi.web.core.filter;

import com.eic.framework.core.security.SecurityContext;
import com.eic.framework.core.security.SecuritySession;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录安全校验 过滤器
 * 
 */
public class LoginFilter implements Filter
{
    @Override
    public void init(FilterConfig filterConfig) throws ServletException
    {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException
    {
        try{
            if(request instanceof HttpServletRequest){
                HttpServletRequest req = (HttpServletRequest) request;
                HttpServletResponse resp = (HttpServletResponse) response;
                if(SecuritySession.doFilter(req,resp)){
                    chain.doFilter(request, response);
                }
            }else{
                chain.doFilter(request, response);
            }
        }finally {
            SecurityContext.clear();
        }
    }

    @Override
    public void destroy()
    {

    }
}
